package com.security.manage.search.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.Id;
import java.time.LocalDateTime;
import java.util.Objects;

@Document(indexName = "firewalls",type = "info",replicas = 0)
public class FireWallInfo {

    @Id
    private String id;

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime dateTime;
    @Field(type = FieldType.Keyword)
    private String action;
    @Field(type = FieldType.Keyword)
    private String protocal;
    @Field(type = FieldType.Keyword)
    private String srcIp;
    @Field(type = FieldType.Keyword)
    private String destIp;
    @Field(type = FieldType.Integer)
    private Integer srcPort=0;
    @Field(type = FieldType.Integer)
    private Integer destPort=0;
    @Field(type = FieldType.Long)
    private Long transferSize=0L;
    @Field(type = FieldType.Integer)
    private Integer tcpflags=0;
    @Field(type = FieldType.Integer)
    private Integer tcpsyn=0;
    @Field(type = FieldType.Integer)
    private Integer tcpack=0;
    @Field(type = FieldType.Integer)
    private Integer tcpwin=0;
    @Field(type = FieldType.Integer)
    private Integer icmptype=0;
    @Field(type = FieldType.Integer)
    private Integer icmpcode=0;
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String info="";
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String path;
    @Field(type = FieldType.Integer)
    private Integer ipType=0;//1 表示国外，2表示国内，0 默认表示N/A
    @Field(type = FieldType.Text)
    private String ipRegion="N/A";
    @Field(type = FieldType.Long)
    private Long userId;
    @Field(type = FieldType.Long)
    private Long taskId=0L;
    @Field(type = FieldType.Long)
    private Long deptId;

    @Override
    public String toString() {
        return "FireWallnfo{" +
                "dateTime=" + dateTime +
                ", action='" + action + '\'' +
                ", protocal='" + protocal + '\'' +
                ", srcIp='" + srcIp + '\'' +
                ", destIp='" + destIp + '\'' +
                ", srcPort=" + srcPort +
                ", destPort=" + destPort +
                '}';
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getTaskId() {
        return taskId;
    }

    public void setTaskId(Long taskId) {
        this.taskId = taskId;
    }

    public Integer getIpType() {
        return ipType;
    }

    public void setIpType(Integer ipType) {
        this.ipType = ipType;
    }

    public String getIpRegion() {
        return ipRegion;
    }

    public void setIpRegion(String ipRegion) {
        this.ipRegion = ipRegion;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public LocalDateTime getDateTime() {
        return dateTime;
    }

    public void setDateTime(LocalDateTime dateTime) {
        this.dateTime = dateTime;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getProtocal() {
        return protocal;
    }

    public void setProtocal(String protocal) {
        this.protocal = protocal;
    }

    public String getSrcIp() {
        return srcIp;
    }

    public void setSrcIp(String srcIp) {
        this.srcIp = srcIp;
    }

    public String getDestIp() {
        return destIp;
    }

    public void setDestIp(String destIp) {
        this.destIp = destIp;
    }

    public Integer getSrcPort() {
        return srcPort;
    }

    public void setSrcPort(Integer srcPort) {
        this.srcPort = srcPort;
    }

    public Integer getDestPort() {
        return destPort;
    }

    public void setDestPort(Integer destPort) {
        this.destPort = destPort;
    }

    public Long getTransferSize() {
        return transferSize;
    }

    public void setTransferSize(Long transferSize) {
        this.transferSize = transferSize;
    }

    public Integer getTcpflags() {
        return tcpflags;
    }

    public void setTcpflags(Integer tcpflags) {
        this.tcpflags = tcpflags;
    }

    public Integer getTcpsyn() {
        return tcpsyn;
    }

    public void setTcpsyn(Integer tcpsyn) {
        this.tcpsyn = tcpsyn;
    }

    public Integer getTcpack() {
        return tcpack;
    }

    public void setTcpack(Integer tcpack) {
        this.tcpack = tcpack;
    }

    public Integer getTcpwin() {
        return tcpwin;
    }

    public void setTcpwin(Integer tcpwin) {
        this.tcpwin = tcpwin;
    }

    public Integer getIcmptype() {
        return icmptype;
    }

    public void setIcmptype(Integer icmptype) {
        this.icmptype = icmptype;
    }

    public Integer getIcmpcode() {
        return icmpcode;
    }

    public void setIcmpcode(Integer icmpcode) {
        this.icmpcode = icmpcode;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Long getDeptId() {
        return deptId;
    }

    public void setDeptId(Long deptId) {
        this.deptId = deptId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        FireWallInfo wallnfo = (FireWallInfo) o;
        return Objects.equals(dateTime, wallnfo.dateTime) &&
                Objects.equals(srcIp, wallnfo.srcIp) &&
                Objects.equals(destIp, wallnfo.destIp);
    }

    @Override
    public int hashCode() {
        return Objects.hash(dateTime, srcIp, destIp);
    }


}
